import { createSlice,createAsyncThunk } from '@reduxjs/toolkit' 
import axios from 'axios'
// 因为是做 异步操作 不能走正常的 action =》 reducer
export const fetchHomeMultidataAction = createAsyncThunk('fetch/homemultidata',
  async (param)=>{
    console.log("fetchHomeMultidataAction",param);
    const res = await axios.get('http:123.207.32.32:8000/home/multidata')
    return res.data
  }
)

const homeSlice = createSlice({
  name:'home',
  homeState:{
    banners:[],
    recommends:[],
  },
  reducers:{
    // changeBanners(state,{payload}){
    //   state.banners = payload
    // },
    // changeRecommends(state, { payload }) {
    //   state.recommends = payload
    // }
  },
  extraReducers:{
    [fetchHomeMultidataAction.pending](state,action){
      console.log("fetchHomeMultidataAction",action);
      const payload = action.payload
      state.banners = payload.data.banners.list
    }
  }
})

export const { changeBanners,changeRecommends}  = homeSlice.actions

export default homeSlice.red